#include"hnurm_dart/Light.h"

Light::Light(cv::Point2d d1,cv::Point2d d2,cv::Point2d d3,cv::Point2d d4,double Area){
    dot[0]=d1;
    dot[1]=d2;
    dot[2]=d3;
    dot[3]=d4;

    light_rect=Rect2f(dot[0],Size(dot[1].x-dot[0].x,dot[3].y-dot[0].y));
    center={(dot[0].x+dot[2].x)/2,(dot[0].y+dot[2].y)/2};
    area=Area;
}

Light::Light(Rect2f& rect,double Area){
    dot[0]=Point2d(rect.x,rect.y);
    dot[1]=Point2d(rect.x+rect.width,rect.y);
    dot[2]=Point2d(rect.x+rect.width,rect.y+rect.height);
    dot[3]=Point2d(rect.x,rect.y+rect.height);
 
    light_rect=rect;
    center={(dot[0].x+dot[2].x)/2,(dot[0].y+dot[2].y)/2};
    area=Area;
}

void Light::set_rect(cv::Point2d d1,cv::Point2d d2,cv::Point2d d3,cv::Point2d d4){
    dot[0]=d1;
    dot[1]=d2;
    dot[2]=d3;
    dot[3]=d4;

    light_rect=Rect2f(dot[0],Size(dot[1].x-dot[0].x,dot[3].y-dot[0].y));
    center={(dot[0].x+dot[2].x)/2,(dot[0].y+dot[2].y)/2};
}

void Light::set_rect(Rect2f rect){
    dot[0]=Point2d(rect.x,rect.y);
    dot[1]=Point2d(rect.x+rect.width,rect.y);
    dot[2]=Point2d(rect.x+rect.width,rect.y+rect.height);
    dot[3]=Point2d(rect.x,rect.y+rect.height);

    light_rect=rect;
    center={(dot[0].x+dot[2].x)/2,(dot[0].y+dot[2].y)/2};
}

void Light::restart()
{
    center={0.0,0.0};
    area=0;
    dot[0]={0.0,0.0};    
    dot[1]={0.0,0.0};    
    dot[2]={0.0,0.0};    
    dot[3]={0.0,0.0};    
    light_rect=Rect2f(dot[0],Size(0,0));
}